package cn.meizhu.serve.service.impl;

import cn.meizhu.base.service.impl.BaseServiceImpl;
import cn.meizhu.org.domain.Employee;
import cn.meizhu.pet.domain.Pet;
import cn.meizhu.pet.domain.PetDetail;
import cn.meizhu.serve.domain.Product;
import cn.meizhu.serve.domain.ProductDetail;
import cn.meizhu.serve.mapper.ProductDetailMapper;
import cn.meizhu.serve.mapper.ProductMapper;
import cn.meizhu.serve.service.IProductService;
import cn.meizhu.util.LoginContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductDetailMapper productDetailMapper;

    @Override
    public void onsale(List<Long> list) {
        productMapper.onsale(list);
    }

    @Override
    public void offsale(List<Long> list) {
        productMapper.offsale(list);
    }

    @Override
    public void dels(Long[] ids) {
        productMapper.dels(ids);
    }

    @Override
    public Product findByIdDetail(Long id) {
        Product product = productMapper.findByIdDetail(id);
        ProductDetail productDetail = productDetailMapper.findByPetId(product.getId());
        product.setDetail(productDetail);
        return product;

    }

    @Override
    public void save(Product product) {
        super.save(product);
        product.getDetail().setProduct_id(product.getId());
        System.out.println(product.getDetail()+"111");
        System.out.println(product.getId());
        productDetailMapper.save(product.getDetail());

    }
}
